package com.ygxsk.carhome.ui.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.allen.library.SuperTextView;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.ui.park.ParkingBundleActivity;
import com.ygxsk.carhome.ui.park.ParkingSpaceBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.Date;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/1/6  10:10
 * @Description:顶部车位的 标题选中
 */
public class RootNodeProvider extends BaseNodeProvider {

    private Activity mActivity;

    public RootNodeProvider(Activity _activity) {
        mActivity = _activity;

//        addChildClickViewIds(R.id.textviewlevelone);

    }

    @Override
    public int getItemViewType() {
        return 0;
    }

    @Override
    public int getLayoutId() {
//        return R.layout.item_expandable_lv0;
        return R.layout.item_expandable_lvtrans;
    }

    @Override
    public void convert(@NonNull BaseViewHolder baseViewHolder, BaseNode baseNode) {

        if (baseNode != null) {

            ParkingSpaceBean parkingSpaceBean = (ParkingSpaceBean) baseNode;

            if (parkingSpaceBean != null) {

                //填充第一级别停车位的标题内容
                String spaceName = parkingSpaceBean.getParkSpaceStr();

                //车辆车位信息等
                SuperTextView textViewOne = (SuperTextView) baseViewHolder.getView(R.id.textviewlevelonetrs);
                //右侧箭头
//                SuperTextView textViewLevelOneArrow = (SuperTextView) baseViewHolder.getView(R.id.textviewlevelonearrow);
                //添加车牌的按钮逻辑
                RoundTextView roundTextViewCarNumAdd = (RoundTextView) baseViewHolder.getView(R.id.roundtextviewhascontactedtrs);

                textViewOne.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

//                        RootNodeProvider.this.onClick(baseViewHolder,textviewone,get);
                        int index = baseViewHolder.getLayoutPosition();

                        getAdapter().expandOrCollapse(index);

                    }
                });

                //默认设置一个向下的箭头,可能有点渐变的延迟:根据 isExpanded 变换箭头的向下或者向上。
                textViewOne.setRightIcon(parkingSpaceBean.isExpanded() //
                        ? ContextCompat.getDrawable(getContext(), R.drawable.jiantxia)//
                        : ContextCompat.getDrawable(getContext(), R.drawable.jiantsh));//

                //暂时先不用
                //TextView textviewOneHelp = (TextView)holder.getView(R.id.textviewonehelp);
//                textViewOne.setLeftTextIsBold(true);//设置左侧文字加粗。
//                textviewone.setTopDividerLineColor(ColorUtils.getColor(R.color.gray19));
//                textViewOne.setLeftString(spaceName);

                //==================================================================================================
                //2021-3-10 16:00:52 添加新需求是车位底下添加一个时间：有效期至 和 可用 天数。。
                //有效期剩余的天数：
                String availableDay = parkingSpaceBean.getAvailableDay();
                Date endTime = parkingSpaceBean.getParkingEndTime();
                String resultTime = CommUtils.methodTimeCutIntoSections(endTime);

                //有效期和可用天数之间该有个空格分隔。
//                String buttomTextView = "有效期至:" + resultTime + getContext().getResources().getString(R.string.kongge0) + "可用:" + availableDay + "天";
                String middleTextView = mActivity.getString(R.string.middle_text_value) + resultTime;
                String bottomTextView = mActivity.getString(R.string.bottom_textview_value) + availableDay + mActivity.getString(R.string.unit_day);

                textViewOne.setLeftTopString(spaceName);
                textViewOne.getLeftTopTextView().setTextSize(17f);
                textViewOne.getLeftTopTextView().setPadding(0, 20, 0, 10);
                textViewOne.setLeftTopTextIsBold(true);//顶部文字加粗

                textViewOne.setLeftString(middleTextView);
                textViewOne.setLeftTextColor(ColorUtils.getColor(R.color.headmanblue));

                textViewOne.setLeftBottomString(bottomTextView);
                textViewOne.setLeftBottomTextColor(ColorUtils.getColor(R.color.headmanblue));
                textViewOne.getLeftBottomTextView().setPadding(0, 0, 0, 10);


                //textviewone.setLeftBottomTextColor(ColorUtils.getColor(R.color.graycontent));


                if (roundTextViewCarNumAdd != null) {

                    roundTextViewCarNumAdd.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

//                            String parkingSpaceId = parkingSpaceBean.getParkingSpaceId();

                            Bundle bundle_extra = new Bundle();

                            //携带 该小区的车位id等信息
                            bundle_extra.putString(ExtraKey.EXTRA_PARKINGSPACEID, parkingSpaceBean.getParkingSpaceId());

                            ActivityUtils.startActivity(bundle_extra, ParkingBundleActivity.class);

                        }
                    });

                }

            }

        }

    }

//    @Override
//    public void onClick(@NonNull BaseViewHolder helper, @NonNull View view, BaseNode data, int position) {
//        super.onClick(helper, view, data, position);
//        getAdapter().expandOrCollapse(position);
//    }

    //    @Override
//    public void onClick(@NonNull BaseViewHolder helper, @NonNull View view, BaseNode data, int position) {
////        super.onClick(helper, view, data, position);
//        getAdapter().expandOrCollapse(position);
//    }
}
